<style lang="less">
    @import '../../styles/common.less';
</style>
<template>
	<div>
		<Card :bordered="false" style="height: 100vh;">
			<p slot="title">乐刷支付</p>
			<p>
				<Input v-model="value" placeholder="请输入金额" style="width: 300px"></Input>
				<div style="margin-top: 20px;">
					<Button type="success" long @click="initLeshuaPay">确认付款</Button>
				</div>
			</p>
		</Card>
		<Spin fix v-if="spinShow">支付中...</Spin>
		<Modal
			v-model="isShow"
			title="请在微信或浏览器打开">
			<p>请在微信或浏览器打开!!!</p>
			<p>请在微信或浏览器打开!!!</p>
			<p>请在微信或浏览器打开!!!</p>
		</Modal>
	</div>
</template>

<script>
	var dsq;
export default{
	data() {
		return{
			value:"",
			isAgent:false,
			isShow:false,
			mag:"",
			spinShow:false
		}
	},
	methods:{
		initLeshuaPay(){
			if(!this.isAgent){
				this.isShow=true;
				return;
			}
			
			if(this.value == ""){
				this.$Notice.open({
					title: '请输入金额'
				});
				return;
			}
			
			var parameter={
				productAmount:this.value,
				paymentMethod:this.isAgent,
				merchantUuid: "ff8080817b49529b017b495345830000",
			}
			
			if(this.isAgent==1){
				
				if(localStorage.getItem("openId")){
					parameter.openId=localStorage.getItem("openId");
				}else{
					this.getOpenId()
				}
				
			}
			this.spinShow=true;
			this.$http.post("/consumer/initLeshuaPay", this.common.request(parameter)).then((res)=>{
				console.log(res.data.body)
				this.mag=res.data.body.data;
				window.location.href=this.mag.jspayUrl; 
			})
		},
		getOpenId(){
			console.log(window.location.href)
			
			if(!localStorage.getItem("openId")){
				window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx76085fe985f8e232&redirect_uri=http://admin.zhaimejia.cn/#/H5LePay&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect"
			}
			
			
			
		},
		browserJudgment () {
			var ua = window.navigator.userAgent.toLowerCase();
			if (ua.match(/MicroMessenger/i) == 'micromessenger') { 
				this.isAgent=1;
			    console.log('微信端');
				this.getOpenId();
			} else if(ua.match(/Alipay/i)=="alipay"){   
				console.log('支付宝端');
				this.isAgent=2;
			}else{
				console.log('其他浏览器');
				this.isShow=true;
				this.isAgent=false;
			}
		},
		//查询是否支付
		isPay(){
			
			var url=window.location.href.split('?')[1].split('&')[0].split('=');
			this.mag=url
			
			if(this.mag[0] == "orderNo"){
				this.spinShow=false;
				this.$http.post("/consumer/inquiryLeshuaOrder", this.common.request({"orderNo":this.mag[1]})).then((res)=>{
					this.mag=res.data.body.data;
					// console.log(this.mag)
					this.$router.push({
						name:'H5isPay',
						params:{
							msg:this.mag
						}
					})
				})
			}
		}
	},
	mounted() {
		this.browserJudgment();
		this.isPay();
	}
}
</script>

<style>
</style>
